package com.leo.huawei;

import java.util.Calendar;
import java.util.Scanner;

/**
 * Created by LEO on 2018/4/18.
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int years = in.nextInt();//表示距离1900年1月1日的年数
        int weeks = in.nextInt();//表示星期数（分别用0——6代表星期日到星期六）
        if (years < 0 || years>400 || weeks<0 || weeks >6){
            System.out.println(-1);
            return;
        }
        long res = 0;

//        Calendar calendar = new GregorianCalendar();
//        for (int i = 0; i < years; i++) {
//            for (int j = 0; j < 12; j++) {
//                calendar.set(1990+i, j, 13);
//                int week = calendar.get(Calendar.DAY_OF_WEEK);
//                if (week -1 == weeks){ res++; }
//            }
//        }
//        System.out.println(res);


        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.DATE, 13);
        for (int i = 0; i < years; i++) {
            calendar.set(Calendar.YEAR, 1990+i);
            for (int j = 0; j < 12; j++) {
                calendar.set(Calendar.MONTH, j);
                int week = calendar.get(Calendar.DAY_OF_WEEK);
                if (week-1 == weeks){ res++; }
            }
        }
        System.out.println(res);
    }
}
